package com.solace.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.support.ErrorMessage;

import java.util.Date;

@SpringBootApplication
@EnableBinding(Sink.class)
public class SolaceStreamApp {

    private static final Logger LOGGER = LoggerFactory.getLogger(SolaceStreamApp.class);
    public static void main(String[] args) {
        SpringApplication.run(SolaceStreamApp.class, args);
    }

    @StreamListener(Sink.INPUT)
    public void receive(Object payload) {
        LOGGER.info("Received: {},{}", payload,new Date());
        throw new RuntimeException("error!");
    }

    @StreamListener("errorChannel")
    public void handleError(ErrorMessage errorMessage) {
        LOGGER.error("exception occurred. errorMessage = {}", errorMessage);
    }
}
